<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'main_chn.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="qczlm/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="qczlm/easyui/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="qczlm/easyui/demo/demo.css">
	<script type="text/javascript" src="qczlm/easyui/js/jquery.min.js"></script>
	<script type="text/javascript" src="qczlm/easyui/js/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="qczlm/easyui/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>
	<h2>审核权限</h2>
	<div style="margin:20px 0;"></div>
	
	<table id="dg" title="权限申请列表" style="width:900px;height:380px" data-options="
				rownumbers:true,
				singleSelect:true,
				autoRowHeight:false,
				pagination:true,
				pageSize:10">
		<thead>
			<tr>
				<th field="id" width="80">编号</th>
				<th field="branch_id" width="50">权限ID</th>
				<th field="username" width="100">申请人</th>
				<th field="creattime" width="200">申请时间</th>
				<th field="channel_key" width="200" align="right">关键字</th>
				<th field="channel_name" width="100" align="right">权限名称</th>
				<th field="status" width="100" align="right">审核状态</th><a accesskey="" >
			</tr>
		</thead>
	</table>
	<script>
		function getData(l){
			var rows = [];
			var status;
			var strHtml;
			for(var i=0; i<l.length;i++){
				status=l[i].status=='0'?'禁用':'审核通过';
				if(status=='审核通过'){
					strHtml="<a class='vl'  href='javascript:void(0)' avalue="+l[i].branch_id+","+l[i].id+",0>"+status+"</a>";
				}else{
					strHtml="<a class='vl' href='javascript:void(0)' avalue="+l[i].branch_id+","+l[i].id+",1>"+status+"</a>";
				}
				rows.push({
					id: l[i].id,
					branch_id: l[i].branch_id,
					username: l[i].username,
					creattime: formatDate(new Date(l[i].creattime)),
					channel_key: l[i].channel_key,
					channel_name: l[i].channel_name,
					status:strHtml
				});
			}
			return rows;
		}
		
		function pagerFilter(data){
			if (typeof data.length == 'number' && typeof data.splice == 'function'){	
				data = {
					total: data.length,
					rows: data
				}
			}
			var dg = $(this);
			var opts = dg.datagrid('options');
			var pager = dg.datagrid('getPager');
			pager.pagination({
				onSelectPage:function(pageNum, pageSize){
					opts.pageNumber = pageNum;
					opts.pageSize = pageSize;
					pager.pagination('refresh',{
						pageNumber:pageNum,
						pageSize:pageSize
					});
					dg.datagrid('loadData',data);
				}
			});
			if (!data.originalRows){
				data.originalRows = (data.rows);
			}
			var start = (opts.pageNumber-1)*parseInt(opts.pageSize);
			var end = start + parseInt(opts.pageSize);
			data.rows = (data.originalRows.slice(start, end));
			return data;
		}
		
		$(function(){
			var list='${list}';
			if(list!=''){
				var l = eval("("+list+")");
				$('#dg').datagrid({loadFilter:pagerFilter}).datagrid('loadData', getData(l));
			}
			$(".vl").on("click",function(){
				var values=$(this).attr("avalue");
				var value = values.split(",");
				alert(value);
				var txt=$(this).text();
				var status;
				if(txt=="禁用"){
					status=1;
				}else{
					status=0;
				}
				$.ajax({
					url:'mexamine/update',
					type:'post',
					data:{branch_id:value[0],id:value[1],status:value[2]},
					dataType:'json',
					success:function(JR){
						if(JR==true){	
							window.location.reload();
						}			
					}
				});
			});
		});
		function tt(){
			alert($(this).val());
		}
		function formatDate(now){     
			var year=now.getFullYear();     
			var month=now.getMonth()+1;     
			var date=now.getDate();     
			var hour=now.getHours();     
			var minute=now.getMinutes();     
			var second=now.getSeconds();     
			return year+"/"+month+"/"+date+" "+hour+":"+minute+":"+second;     
		}
	</script>
  </body>
</html>
